package lanou.autohome.forum.adapters;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import lanou.autohome.R;
import lanou.autohome.basetool.NetTool;
import lanou.autohome.forum.beans.ForumFeatureAllBean;

/**
 * Created by dllo on 16/8/18.
 */
public class ForumFeatureAllAdapter extends BaseAdapter{

    private Context mcontext;
    private ForumFeatureAllBean forumFeatureAllBean;
    private int urlAdd;

    public int getUrlAdd() {
        return urlAdd;
    }

    public void setUrlAdd(int urlAdd) {
        this.urlAdd = urlAdd;
    }

    public ForumFeatureAllAdapter(Context mcontext) {
        this.mcontext = mcontext;
    }

    public void setForumFeatureAllBean(ForumFeatureAllBean forumFeatureAllBean) {
        this.forumFeatureAllBean = forumFeatureAllBean;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return forumFeatureAllBean != null ? forumFeatureAllBean.getResult().getList().size() :0;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if(convertView == null){
            convertView = LayoutInflater.from(mcontext).inflate(R.layout.item_forum_feature_all,null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder)convertView.getTag();
        }

        ForumFeatureAllBean.ResultBean.ListBean bean = forumFeatureAllBean.getResult().getList().get(position);

        viewHolder.bbsname.setText(bean.getBbsname());
        viewHolder.title.setText(bean.getTitle());
        Log.d("Vampire", bean.getTitle());
        viewHolder.replycounts.setText(String.valueOf(bean.getReplycounts()) + "回");
        NetTool netTool = new NetTool();
        netTool.getImage(bean.getSmallpic() , viewHolder.smallpic);
        urlAdd = forumFeatureAllBean.getResult().getList().get(position).getTopicid();

        return convertView;
    }

    public class ViewHolder{
        ImageView smallpic;
        TextView title;
        TextView replycounts;
        TextView bbsname;
        public ViewHolder(View convertView){
            smallpic = (ImageView) convertView.findViewById(R.id.smallpic_forum_feature_all_item);
            title = (TextView) convertView.findViewById(R.id.title_forum_feature_all_item);
            replycounts = (TextView) convertView.findViewById(R.id.replycounts_forum_feature_all_item);
            bbsname = (TextView) convertView.findViewById(R.id.bbsname_forum_feature_all_item);
        }

    }
}
